package com.liuwei.msmall.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Classname ThreadPoolConfig
 * @Description TODO
 * @Date 2020/6/23 15:33
 * @Created by 刘
 */

/**
 * 向容器中添加一个自定义的线程池
 *
 */
@Configuration
public class ThreadPoolConfig {


    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolProperties poolProperties){

        /**
         * 将以下属性配置到配置文件中
         * 可以使用配置文件进行配置
         * int corePoolSize,
         int maximumPoolSize,
         long keepAliveTime,

         */
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(poolProperties.getCorePoolSize(),
                poolProperties.getMaximumPoolSize(), poolProperties.getKeepAliveTime(),
                TimeUnit.SECONDS, new LinkedBlockingDeque<>(10000),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        return threadPoolExecutor;
    }


}
